var zclsh = decodeURI(Common.GetRequest().zclsh); //获取传入的update
var zydm = decodeURI(Common.GetRequest().zydm);//值域代码
if (zclsh == "update") {
    queryZj();
}
//数据校验-服务名称
function validate() {
    var zydm = $.trim($("#zydm").val());
    if (zydm == '') {
        LayerWn.showAlert('值域代码不能为空');
        return false;
    }
    var zymc = $.trim($("#zymc").val());
    if (zymc == '') {
        LayerWn.showAlert('值域名称不能为空');
        return false;
    }
    var zylbsm = $.trim($("#zylbsm").val());
    if (zylbsm == '') {
        LayerWn.showAlert('值域分类不能为空');
        return false;
    }
    return true;
}
/**
 * 保存/更新
 */
function save() {
    if(!validate())
        return false;
    var data = $("form").serializeJson();
    var url = "zygl/saveZy";
    var zclsh = Common.GetRequest().zclsh; //获取传入的update
    if (zclsh == "update") {
        url = "zygl/updateZy";
        data.zydm = zydm;
    }
    var formJSON = JSON.stringify(data);
    $.ajax({
        type: "POST",
        contentType: 'application/json',
        dataType: "json",
        url: url,
        data: formJSON,
        success: function (jsonData) {
            if (jsonData.code == 200) {   //保存成功
                for (var k = 0; k < parent.frames.length; k++) {
                    if (parent.frames[k].frameElement.src.indexOf("psms-zygl.html") != -1){
                        parent.frames[k].callbackTree(jsonData.zy.zydm);
                    }
                }
                LayerWn.showSucAlert('保存成功');
                setTimeout(function () {
                    parent.layer.closeAll()
                }, 1000);
            } else if(jsonData.code == 201) {
                LayerWn.showAlert(jsonData.msg);
            }
        }
    });
}
/*查询值域*/
function queryZj() {
    var queryParms={zydm:zydm};
    $.ajax({
        type: "GET",
        contentType: 'application/json',
        dataType: "json",
        url: "zygl/getZy",
        data: queryParms,
        success: function (jsonData) {
            if (jsonData.code == 200) {
                $('#appForm').populateForm(jsonData.zy);
                //值编码不可编辑
                $("#zydm").attr("disabled","disabled");
                $("#zylbsm").attr("disabled","disabled");
            } else {
            }
        }
    });
}
/**
 * 取消按钮
 */
function cancel() {
    parent.layer.closeAll();
}